package org.cyk.bilibili_json_read.api;

import org.cyk.bilibili_json_read.model.JsonContentDTO;
import org.cyk.bilibili_json_read.service.IReadJsonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin("*")
@RequestMapping("/read_json")
public class ReadJsonApi {

    @Autowired
    private IReadJsonService readJsonService;

    @PostMapping
    public String read(
            @RequestBody JsonContentDTO jsonContent
            ) {
        if(jsonContent == null || !StringUtils.hasLength(jsonContent.getJson())) {
            return "";
        }
        return readJsonService.readJson(jsonContent);
    }

}
